package com.simbaliu3.controller;

import com.simbaliu3.model.UserEntity;
import com.simbaliu3.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by Administrator on 2017/5/24.
 */
@Controller
public class MainController {

    @Autowired
    UserRepository userRepository;

    //首页
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        return "index";
    }

    //登录
    @RequestMapping(value = "index/login", method = RequestMethod.POST)
    public String loginResult(@ModelAttribute("user") UserEntity userEntity) {
        if (null != userRepository.loginCheck(userEntity.getPhone(), userEntity.getPwd())) {
            System.out.println("success");
        } else {
            System.out.println("failed");
        }
        return "";
    }

    //跳转到注册
    @RequestMapping(value = "index/register", method = RequestMethod.GET)
    public String jumpRegister() {
        return "users/register";
    }

    //注册
    @RequestMapping(value = "/users/register/registerP", method = RequestMethod.POST)
    public String registerResult(@ModelAttribute("user") UserEntity userEntity) {
        userRepository.saveAndFlush(userEntity);
        return "";
    }

}
